/**
 * Copyright &copy; 2013-2018 青岛数码人网络科技有限公司   All rights reserved.
 */
package cn.net.ecode.elec.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.net.ecode.common.config.Global;
import cn.net.ecode.common.persistence.Page;
import cn.net.ecode.common.web.BaseController;
import cn.net.ecode.common.utils.StringUtils;
import cn.net.ecode.elec.entity.ElecAgencyDeal;
import cn.net.ecode.elec.service.ElecAgencyDealService;

/**
 * 代理企业-电力交易Controller
 * @author xiaodunshan
 * @version 2019-09-28
 */
@Controller
@RequestMapping(value = "${adminPath}/elec/elecAgencyDeal")
public class ElecAgencyDealController extends BaseController {

	@Autowired
	private ElecAgencyDealService elecAgencyDealService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ElecAgencyDeal get(String id, boolean isNewRecord) {
		return elecAgencyDealService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("elec:elecAgencyDeal:view")
	@RequestMapping(value = {"list", ""})
	public String list(ElecAgencyDeal elecAgencyDeal, Model model) {
		model.addAttribute("elecAgencyDeal", elecAgencyDeal);
		return "ecode/elec/elecAgencyDealList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("elec:elecAgencyDeal:view")
	@ResponseBody
	@RequestMapping(value = "listData")
	public Page<ElecAgencyDeal> listData(ElecAgencyDeal elecAgencyDeal, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ElecAgencyDeal> page = elecAgencyDealService.findPage(new Page<ElecAgencyDeal>(request, response), elecAgencyDeal); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("elec:elecAgencyDeal:view")
	@RequestMapping(value = "form")
	public String form(ElecAgencyDeal elecAgencyDeal, Model model) {
		model.addAttribute("elecAgencyDeal", elecAgencyDeal);
		return "ecode/elec/elecAgencyDealForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("elec:elecAgencyDeal:edit")
	@ResponseBody
	@RequestMapping(value = "save")
	public String save(ElecAgencyDeal elecAgencyDeal) {
		StringBuilder message = new StringBuilder();
		if (!beanValidator(message, elecAgencyDeal)){
			return renderResult(Global.FALSE, message);
		}
		elecAgencyDealService.save(elecAgencyDeal);
		return renderResult(Global.TRUE, "保存代理企业-电力交易成功！");
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("elec:elecAgencyDeal:edit")
	@ResponseBody
	@RequestMapping(value = "delete")
	public String delete(ElecAgencyDeal elecAgencyDeal) {
		elecAgencyDealService.delete(elecAgencyDeal);
		return renderResult(Global.TRUE, "删除代理企业-电力交易成功！");
	}

}